home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / rs6000 / rs6000.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  75KB  |  2,655 lines

  1. /* Subroutines used for code generation on IBM RS/6000.
  2.    Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
  3.    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include "config.h"
  25. #include "rtl.h"
  26. #include "regs.h"
  27. #include "hard-reg-set.h"
  28. #include "real.h"
  29. #include "insn-config.h"
  30. #include "conditions.h"
  31. #include "insn-flags.h"
  32. #include "output.h"
  33. #include "insn-attr.h"
  34. #include "flags.h"
  35. #include "recog.h"
  36. #include "expr.h"
  37. #include "obstack.h"
  38. #include "tree.h"
  39.  
  40. extern char *language_string;
  41. extern int profile_block_flag;
  42.  
  43. #define min(A,B)    ((A) < (B) ? (A) : (B))
  44. #define max(A,B)    ((A) > (B) ? (A) : (B))
  45.  
  46. /* Target cpu type */
  47.  
  48. enum processor_type rs6000_cpu;
  49. char *rs6000_cpu_string;
  50.  
  51. /* Set to non-zero by "fix" operation to indicate that itrunc and
  52.    uitrunc must be defined.  */
  53.  
  54. int rs6000_trunc_used;
  55.  
  56. /* Set to non-zero once they have been defined.  */
  57.  
  58. static int trunc_defined;
  59.  
  60. /* Set to non-zero once AIX common-mode calls have been defined.  */
  61. static int common_mode_defined;
  62. /* Save information from a "cmpxx" operation until the branch or scc is
  63.    emitted.  */
  64.  
  65. rtx rs6000_compare_op0, rs6000_compare_op1;
  66. int rs6000_compare_fp_p;
  67.  
  68. #ifdef USING_SVR4_H
  69. /* Label number of label created for -mrelocatable, to call to so we can
  70.    get the address of the GOT section */
  71. int rs6000_pic_labelno;
  72. #endif
  73.  
  74. /* Override command line options.  Mostly we process the processor
  75.    type and sometimes adjust other TARGET_ options.  */
  76.  
  77. void
  78. rs6000_override_options ()
  79. {
  80.   int i;
  81.  
  82.   /* Simplify the entries below by making a mask for any POWER
  83.      variant and any PowerPC variant.  */
  84.  
  85. #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
  86. #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
  87.                | MASK_PPC_GFXOPT | MASK_POWERPC64)
  88. #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
  89.  
  90.   static struct ptt
  91.     {
  92.       char *name;        /* Canonical processor name.  */
  93.       enum processor_type processor; /* Processor type enum value.  */
  94.       int target_enable;    /* Target flags to enable.  */
  95.       int target_disable;    /* Target flags to disable.  */
  96.     } processor_target_table[]
  97.       = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
  98.      {"power", PROCESSOR_POWER,
  99.         MASK_POWER | MASK_MULTIPLE | MASK_STRING,
  100.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  101.      {"powerpc", PROCESSOR_POWERPC,
  102.         MASK_POWERPC | MASK_NEW_MNEMONICS,
  103.         POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
  104.      {"rios", PROCESSOR_RIOS1,
  105.         MASK_POWER | MASK_MULTIPLE | MASK_STRING,
  106.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  107.      {"rios1", PROCESSOR_RIOS1,
  108.         MASK_POWER | MASK_MULTIPLE | MASK_STRING,
  109.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  110.      {"rsc", PROCESSOR_PPC601,
  111.         MASK_POWER | MASK_MULTIPLE | MASK_STRING,
  112.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  113.      {"rsc1", PROCESSOR_PPC601,
  114.         MASK_POWER | MASK_MULTIPLE | MASK_STRING,
  115.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  116.      {"rios2", PROCESSOR_RIOS2,
  117.         MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
  118.         POWERPC_MASKS | MASK_NEW_MNEMONICS},
  119.      {"403", PROCESSOR_PPC403,
  120.         MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
  121.         POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
  122.      {"mpc403", PROCESSOR_PPC403,
  123.         MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
  124.         POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
  125.      {"ppc403", PROCESSOR_PPC403,
  126.         MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
  127.         POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
  128.      {"601", PROCESSOR_PPC601,
  129.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
  130.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  131.      {"mpc601", PROCESSOR_PPC601,
  132.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
  133.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  134.      {"ppc601", PROCESSOR_PPC601,
  135.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
  136.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  137.      {"603", PROCESSOR_PPC603,
  138.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  139.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  140.      {"mpc603", PROCESSOR_PPC603,
  141.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  142.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  143.      {"ppc603", PROCESSOR_PPC603,
  144.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  145.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  146.      {"604", PROCESSOR_PPC604,
  147.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  148.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  149.      {"mpc604", PROCESSOR_PPC604,
  150.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  151.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  152.      {"ppc604", PROCESSOR_PPC604,
  153.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  154.       POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}};
  155.  
  156.   int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
  157.  
  158.   int multiple = TARGET_MULTIPLE;    /* save current -mmultiple/-mno-multiple status */
  159.   int string   = TARGET_STRING;        /* save current -mstring/-mno-string status */
  160.  
  161.   profile_block_flag = 0;
  162.  
  163.   /* Identify the processor type */
  164.   if (rs6000_cpu_string == 0)
  165.     rs6000_cpu = PROCESSOR_DEFAULT;
  166.   else
  167.     {
  168.       for (i = 0; i < ptt_size; i++)
  169.     if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
  170.       {
  171.         rs6000_cpu = processor_target_table[i].processor;
  172.         target_flags |= processor_target_table[i].target_enable;
  173.         target_flags &= ~processor_target_table[i].target_disable;
  174.         break;
  175.       }
  176.  
  177.       if (i == ptt_size)
  178.     {
  179.       error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
  180.       rs6000_cpu_string = "default";
  181.       rs6000_cpu = PROCESSOR_DEFAULT;
  182.     }
  183.     }
  184.  
  185.   /* If -mmultiple or -mno-multiple was explicitly used, don't
  186.      override with the processor default */
  187.   if (TARGET_MULTIPLE_SET)
  188.     target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
  189.  
  190.   /* If -mstring or -mno-string was explicitly used, don't
  191.      override with the processor default */
  192.   if (TARGET_STRING_SET)
  193.     target_flags = (target_flags & ~MASK_STRING) | string;
  194.  
  195.   /* Don't allow -mmultiple or -mstring on little endian systems, because the
  196.      hardware doesn't support the instructions used in little endian mode */
  197.   if (!BYTES_BIG_ENDIAN)
  198.     {
  199.       if (TARGET_MULTIPLE)
  200.     {
  201.       target_flags &= ~MASK_MULTIPLE;
  202.       if (TARGET_MULTIPLE_SET)
  203.         warning ("-mmultiple is not supported on little endian systems");
  204.     }
  205.  
  206.       if (TARGET_STRING)
  207.     {
  208.       target_flags &= ~MASK_STRING;
  209.       if (TARGET_STRING_SET)
  210.         warning ("-mstring is not supported on little endian systems");
  211.     }
  212.     }
  213.  
  214. #ifdef SUBTARGET_OVERRIDE_OPTIONS
  215.   SUBTARGET_OVERRIDE_OPTIONS;
  216. #endif
  217. }
  218.  
  219. /* Create a CONST_DOUBLE like immed_double_const, except reverse the
  220.    two parts of the constant if the target is little endian.  */
  221.  
  222. struct rtx_def *rs6000_immed_double_const (i0, i1, mode)
  223.      HOST_WIDE_INT i0, i1;
  224.      enum machine_mode mode;
  225. {
  226.   if (! WORDS_BIG_ENDIAN)
  227.     return immed_double_const (i1, i0, mode);
  228.  
  229.   return immed_double_const (i0, i1, mode);
  230. }
  231.  
  232.  
  233. /* Return non-zero if this function is known to have a null epilogue.  */
  234.  
  235. int
  236. direct_return ()
  237. {
  238.   return (reload_completed
  239.       && first_reg_to_save () == 32
  240.       && first_fp_reg_to_save () == 64
  241.       && ! regs_ever_live[65]
  242.       && ! rs6000_pushes_stack ());
  243. }
  244.  
  245. /* Returns 1 always.  */
  246.  
  247. int
  248. any_operand (op, mode)
  249.      register rtx op;
  250.      enum machine_mode mode;
  251. {
  252.   return 1;
  253. }
  254.  
  255. /* Return 1 if OP is a constant that can fit in a D field.  */
  256.  
  257. int
  258. short_cint_operand (op, mode)
  259.      register rtx op;
  260.      enum machine_mode mode;
  261. {
  262.   return (GET_CODE (op) == CONST_INT
  263.       && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
  264. }
  265.  
  266. /* Similar for a unsigned D field.  */
  267.  
  268. int
  269. u_short_cint_operand (op, mode)
  270.      register rtx op;
  271.      enum machine_mode mode;
  272. {
  273.   return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
  274. }
  275.  
  276. /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field.  */
  277.  
  278. int
  279. non_short_cint_operand (op, mode)
  280.      register rtx op;
  281.      enum machine_mode mode;
  282. {
  283.   return (GET_CODE (op) == CONST_INT
  284.       && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
  285. }
  286.  
  287. /* Returns 1 if OP is a register that is not special (i.e., not MQ,
  288.    ctr, or lr).  */
  289.  
  290. int
  291. gpc_reg_operand (op, mode)
  292.      register rtx op;
  293.      enum machine_mode mode;
  294. {
  295.   return (register_operand (op, mode)
  296.       && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
  297. }
  298.  
  299. /* Returns 1 if OP is either a pseudo-register or a register denoting a
  300.    CR field.  */
  301.  
  302. int
  303. cc_reg_operand (op, mode)
  304.      register rtx op;
  305.      enum machine_mode mode;
  306. {
  307.   return (register_operand (op, mode)
  308.       && (GET_CODE (op) != REG
  309.           || REGNO (op) >= FIRST_PSEUDO_REGISTER
  310.           || CR_REGNO_P (REGNO (op))));
  311. }
  312.  
  313. /* Returns 1 if OP is either a constant integer valid for a D-field or a
  314.    non-special register.  If a register, it must be in the proper mode unless
  315.    MODE is VOIDmode.  */
  316.  
  317. int
  318. reg_or_short_operand (op, mode)
  319.       register rtx op;
  320.       enum machine_mode mode;
  321. {
  322.   return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
  323. }
  324.  
  325. /* Similar, except check if the negation of the constant would be valid for
  326.    a D-field.  */
  327.  
  328. int
  329. reg_or_neg_short_operand (op, mode)
  330.       register rtx op;
  331.       enum machine_mode mode;
  332. {
  333.   if (GET_CODE (op) == CONST_INT)
  334.     return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
  335.  
  336.   return gpc_reg_operand (op, mode);
  337. }
  338.  
  339. /* Return 1 if the operand is either a register or an integer whose high-order
  340.    16 bits are zero.  */
  341.  
  342. int
  343. reg_or_u_short_operand (op, mode)
  344.      register rtx op;
  345.      enum machine_mode mode;
  346. {
  347.   if (GET_CODE (op) == CONST_INT
  348.       && (INTVAL (op) & 0xffff0000) == 0)
  349.     return 1;
  350.  
  351.   return gpc_reg_operand (op, mode);
  352. }
  353.  
  354. /* Return 1 is the operand is either a non-special register or ANY
  355.    constant integer.  */
  356.  
  357. int
  358. reg_or_cint_operand (op, mode)
  359.     register rtx op;
  360.     enum machine_mode mode;
  361. {
  362.      return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
  363. }
  364.  
  365. /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
  366.    with one instruction per word.  We only do this if we can safely read
  367.    CONST_DOUBLE_{LOW,HIGH}.  */
  368.  
  369. int
  370. easy_fp_constant (op, mode)
  371.      register rtx op;
  372.      register enum machine_mode mode;
  373. {
  374.   rtx low, high;
  375.  
  376.   if (GET_CODE (op) != CONST_DOUBLE
  377.       || GET_MODE (op) != mode
  378.       || GET_MODE_CLASS (mode) != MODE_FLOAT)
  379.     return 0;
  380.  
  381.   high = operand_subword (op, 0, 0, mode);
  382.   low = operand_subword (op, 1, 0, mode);
  383.  
  384.   if (high == 0 || ! input_operand (high, word_mode))
  385.     return 0;
  386.  
  387.   return (mode == SFmode
  388.       || (low != 0 && input_operand (low, word_mode)));
  389. }
  390.       
  391. /* Return 1 if the operand is a constant whose low-order 32 bits are
  392.    zero.  */
  393.  
  394. int
  395. low_32_bit_operand (op, mode)
  396.      register rtx op;
  397.      enum machine_mode mode;
  398. {
  399.   rtx low;
  400.  
  401.   if (GET_CODE (op) != CONST_DOUBLE && GET_CODE (op) != CONST_INT)
  402.     return 0;
  403.  
  404.   low = operand_subword (op, 1, 0, mode);
  405.   return low != 0 && GET_CODE (low) == CONST_INT && INTVAL (low) == 0;
  406. }
  407.  
  408. /* Return 1 if the operand is either a floating-point register, a pseudo
  409.    register, or memory.  */
  410.  
  411. int
  412. fp_reg_or_mem_operand (op, mode)
  413.      register rtx op;
  414.      enum machine_mode mode;
  415. {
  416.   return (memory_operand (op, mode)
  417.       || (register_operand (op, mode)
  418.           && (GET_CODE (op) != REG
  419.           || REGNO (op) >= FIRST_PSEUDO_REGISTER
  420.           || FP_REGNO_P (REGNO (op)))));
  421. }
  422.  
  423. /* Return 1 if the operand is either an easy FP constant (see above) or
  424.    memory.  */
  425.  
  426. int
  427. mem_or_easy_const_operand (op, mode)
  428.      register rtx op;
  429.      enum machine_mode mode;
  430. {
  431.   return memory_operand (op, mode) || easy_fp_constant (op, mode);
  432. }
  433.  
  434. /* Return 1 if the operand is either a non-special register or an item
  435.    that can be used as the operand of an SI add insn.  */
  436.  
  437. int
  438. add_operand (op, mode)
  439.     register rtx op;
  440.     enum machine_mode mode;
  441. {
  442.   return (reg_or_short_operand (op, mode)
  443.       || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
  444. }
  445.  
  446. /* Return 1 if OP is a constant but not a valid add_operand.  */
  447.  
  448. int
  449. non_add_cint_operand (op, mode)
  450.      register rtx op;
  451.      enum machine_mode mode;
  452. {
  453.   return (GET_CODE (op) == CONST_INT
  454.       && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
  455.       && (INTVAL (op) & 0xffff) != 0);
  456. }
  457.  
  458. /* Return 1 if the operand is a non-special register or a constant that
  459.    can be used as the operand of an OR or XOR insn on the RS/6000.  */
  460.  
  461. int
  462. logical_operand (op, mode)
  463.      register rtx op;
  464.      enum machine_mode mode;
  465. {
  466.   return (gpc_reg_operand (op, mode)
  467.       || (GET_CODE (op) == CONST_INT
  468.           && ((INTVAL (op) & 0xffff0000) == 0
  469.           || (INTVAL (op) & 0xffff) == 0)));
  470. }
  471.  
  472. /* Return 1 if C is a constant that is not a logical operand (as
  473.    above).  */
  474.  
  475. int
  476. non_logical_cint_operand (op, mode)
  477.      register rtx op;
  478.      enum machine_mode mode;
  479. {
  480.   return (GET_CODE (op) == CONST_INT
  481.       && (INTVAL (op) & 0xffff0000) != 0
  482.       && (INTVAL (op) & 0xffff) != 0);
  483. }
  484.  
  485. /* Return 1 if C is a constant that can be encoded in a mask on the
  486.    RS/6000.  It is if there are no more than two 1->0 or 0->1 transitions.
  487.    Reject all ones and all zeros, since these should have been optimized
  488.    away and confuse the making of MB and ME.  */
  489.  
  490. int
  491. mask_constant (c)
  492.      register int c;
  493. {
  494.   int i;
  495.   int last_bit_value;
  496.   int transitions = 0;
  497.  
  498.   if (c == 0 || c == ~0)
  499.     return 0;
  500.  
  501.   last_bit_value = c & 1;
  502.  
  503.   for (i = 1; i < 32; i++)
  504.     if (((c >>= 1) & 1) != last_bit_value)
  505.       last_bit_value ^= 1, transitions++;
  506.  
  507.   return transitions <= 2;
  508. }
  509.  
  510. /* Return 1 if the operand is a constant that is a mask on the RS/6000. */
  511.  
  512. int
  513. mask_operand (op, mode)
  514.      register rtx op;
  515.      enum machine_mode mode;
  516. {
  517.   return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
  518. }
  519.  
  520. /* Return 1 if the operand is either a non-special register or a
  521.    constant that can be used as the operand of an RS/6000 logical AND insn.  */
  522.  
  523. int
  524. and_operand (op, mode)
  525.     register rtx op;
  526.     enum machine_mode mode;
  527. {
  528.   return (reg_or_short_operand (op, mode)
  529.       || logical_operand (op, mode)
  530.       || mask_operand (op, mode));
  531. }
  532.  
  533. /* Return 1 if the operand is a constant but not a valid operand for an AND
  534.    insn.  */
  535.  
  536. int
  537. non_and_cint_operand (op, mode)
  538.      register rtx op;
  539.      enum machine_mode mode;
  540. {
  541.   return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
  542. }
  543.  
  544. /* Return 1 if the operand is a general register or memory operand.  */
  545.  
  546. int
  547. reg_or_mem_operand (op, mode)
  548.      register rtx op;
  549.      register enum machine_mode mode;
  550. {
  551.   return gpc_reg_operand (op, mode) || memory_operand (op, mode);
  552. }
  553.  
  554. /* Return 1 if the operand is a general register or memory operand without
  555.    pre-inc or pre_dec which produces invalid form of PowerPC lwa
  556.    instruction.  */
  557.  
  558. int
  559. lwa_operand (op, mode)
  560.      register rtx op;
  561.      register enum machine_mode mode;
  562. {
  563.   rtx inner = op;
  564.  
  565.   if (reload_completed && GET_CODE (inner) == SUBREG)
  566.     inner = SUBREG_REG (inner);
  567.     
  568.   return gpc_reg_operand (inner, mode)
  569.     || (memory_operand (inner, mode)
  570.     && GET_CODE (XEXP (inner, 0)) != PRE_INC
  571.     && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
  572. }
  573.  
  574. /* Return 1 if the operand, used inside a MEM, is a valid first argument
  575.    to CALL.  This is a SYMBOL_REF or a pseudo-register, which will be
  576.    forced to lr.  */
  577.  
  578. int
  579. call_operand (op, mode)
  580.      register rtx op;
  581.      enum machine_mode mode;
  582. {
  583.   if (mode != VOIDmode && GET_MODE (op) != mode)
  584.     return 0;
  585.  
  586.   return (GET_CODE (op) == SYMBOL_REF
  587.       || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
  588. }
  589.  
  590.  
  591. /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
  592.    this file.  */
  593.  
  594. int
  595. current_file_function_operand (op, mode)
  596.      register rtx op;
  597.      enum machine_mode mode;
  598. {
  599.   return (GET_CODE (op) == SYMBOL_REF
  600.       && (SYMBOL_REF_FLAG (op)
  601.           || op == XEXP (DECL_RTL (current_function_decl), 0)));
  602. }
  603.  
  604.  
  605. /* Return 1 if this operand is a valid input for a move insn.  */
  606.  
  607. int
  608. input_operand (op, mode)
  609.      register rtx op;
  610.      enum machine_mode mode;
  611. {
  612.   /* Memory is always valid.  */
  613.   if (memory_operand (op, mode))
  614.     return 1;
  615.  
  616.   /* For floating-point, easy constants are valid.  */
  617.   if (GET_MODE_CLASS (mode) == MODE_FLOAT
  618.       && CONSTANT_P (op)
  619.       && easy_fp_constant (op, mode))
  620.     return 1;
  621.  
  622.   /* For floating-point or multi-word mode, the only remaining valid type
  623.      is a register.  */
  624.   if (GET_MODE_CLASS (mode) == MODE_FLOAT
  625.       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
  626.     return register_operand (op, mode);
  627.  
  628.   /* The only cases left are integral modes one word or smaller (we
  629.      do not get called for MODE_CC values).  These can be in any
  630.      register.  */
  631.   if (register_operand (op, mode))
  632.     return 1;
  633.  
  634.   /* For HImode and QImode, any constant is valid. */
  635.   if ((mode == HImode || mode == QImode)
  636.       && GET_CODE (op) == CONST_INT)
  637.     return 1;
  638.  
  639.   /* A SYMBOL_REF referring to the TOC is valid.  */
  640.   if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
  641.     return 1;
  642.  
  643.   /* Otherwise, we will be doing this SET with an add, so anything valid
  644.      for an add will be valid.  */
  645.   return add_operand (op, mode);
  646. }
  647.  
  648. /* Expand a block move operation, and return 1 if successful.  Return 0
  649.    if we should let the compiler generate normal code.
  650.  
  651.    operands[0] is the destination
  652.    operands[1] is the source
  653.    operands[2] is the length
  654.    operands[3] is the alignment */
  655.  
  656. #define MAX_MOVE_REG 4
  657.  
  658. int
  659. expand_block_move (operands)
  660.      rtx operands[];
  661. {
  662.   rtx bytes_rtx    = operands[2];
  663.   rtx align_rtx = operands[3];
  664.   int constp    = (GET_CODE (bytes_rtx) == CONST_INT);
  665.   int align    = XINT (align_rtx, 0);
  666.   int bytes;
  667.   int offset;
  668.   int num_reg;
  669.   int i;
  670.   rtx src_reg;
  671.   rtx dest_reg;
  672.   rtx src_addr;
  673.   rtx dest_addr;
  674.   rtx tmp_reg;
  675.   rtx stores[MAX_MOVE_REG];
  676.   int move_bytes;
  677.  
  678.   /* If this is not a fixed size move, just call memcpy */
  679.   if (!constp)
  680.     return 0;
  681.  
  682.   /* Anything to move? */
  683.   bytes = INTVAL (bytes_rtx);
  684.   if (bytes <= 0)
  685.     return 1;
  686.  
  687.   /* Don't support real large moves.  If string instructions are not used,
  688.      then don't generate more than 8 loads.  */
  689.   if (TARGET_STRING)
  690.     {
  691.       if (bytes > 4*8)
  692.     return 0;
  693.     }
  694.   else if (!STRICT_ALIGNMENT)
  695.     {
  696.       if (bytes > 4*8)
  697.     return 0;
  698.     }
  699.   else if (bytes > 8*align)
  700.     return 0;
  701.  
  702.   /* Move the address into scratch registers.  */
  703.   dest_reg = copy_addr_to_reg (XEXP (operands[0], 0));
  704.   src_reg  = copy_addr_to_reg (XEXP (operands[1], 0));
  705.  
  706.   if (TARGET_STRING)    /* string instructions are available */
  707.     {
  708.       for ( ; bytes > 0; bytes -= move_bytes)
  709.     {
  710. #if 0
  711.       /* XXX Don't move so many bytes right now, it causes the compiler to not bootstrap */
  712.       if (bytes > 24        /* move up to 32 bytes at a time */
  713.           && !fixed_regs[5]
  714.           && !fixed_regs[6]
  715.           && !fixed_regs[7]
  716.           && !fixed_regs[8]
  717.           && !fixed_regs[9]
  718.           && !fixed_regs[10]
  719.           && !fixed_regs[11]
  720.           && !fixed_regs[12])
  721.         {
  722.           move_bytes = (bytes > 32) ? 32 : bytes;
  723.           emit_insn (gen_movstrsi_8reg (dest_reg,
  724.                         src_reg,
  725.                         GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
  726.                         align_rtx));
  727.         }
  728.       else if (bytes > 16    /* move up to 24 bytes at a time */
  729.            && !fixed_regs[7]
  730.            && !fixed_regs[8]
  731.            && !fixed_regs[9]
  732.            && !fixed_regs[10]
  733.            && !fixed_regs[11]
  734.            && !fixed_regs[12])
  735.         {
  736.           move_bytes = (bytes > 24) ? 24 : bytes;
  737.           emit_insn (gen_movstrsi_6reg (dest_reg,
  738.                         src_reg,
  739.                         GEN_INT (move_bytes),
  740.                         align_rtx));
  741.         }
  742.       else if (bytes > 8    /* move up to 16 bytes at a time */
  743.            && !fixed_regs[9]
  744.            && !fixed_regs[10]
  745.            && !fixed_regs[11]
  746.            && !fixed_regs[12])
  747.         {
  748.           move_bytes = (bytes > 16) ? 16 : bytes;
  749.           emit_insn (gen_movstrsi_4reg (dest_reg,
  750.                         src_reg,
  751.                         GEN_INT (move_bytes),
  752.                         align_rtx));
  753.         }
  754.       else
  755. #endif
  756.         if (bytes > 4 && !TARGET_64BIT)
  757.         {            /* move up to 8 bytes at a time */
  758.           move_bytes = (bytes > 8) ? 8 : bytes;
  759.           emit_insn (gen_movstrsi_2reg (dest_reg,
  760.                         src_reg,
  761.                         GEN_INT (move_bytes),
  762.                         align_rtx));
  763.         }
  764.       else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
  765.         {            /* move 4 bytes */
  766.           move_bytes = 4;
  767.           tmp_reg = gen_reg_rtx (SImode);
  768.           emit_move_insn (tmp_reg, gen_rtx (MEM, SImode, src_reg));
  769.           emit_move_insn (gen_rtx (MEM, SImode, dest_reg), tmp_reg);
  770.         }
  771.       else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
  772.         {            /* move 2 bytes */
  773.           move_bytes = 2;
  774.           tmp_reg = gen_reg_rtx (HImode);
  775.           emit_move_insn (tmp_reg, gen_rtx (MEM, HImode, src_reg));
  776.           emit_move_insn (gen_rtx (MEM, HImode, dest_reg), tmp_reg);
  777.         }
  778.       else if (bytes == 1)    /* move 1 byte */
  779.         {
  780.           move_bytes = 1;
  781.           tmp_reg = gen_reg_rtx (QImode);
  782.           emit_move_insn (tmp_reg, gen_rtx (MEM, QImode, src_reg));
  783.           emit_move_insn (gen_rtx (MEM, QImode, dest_reg), tmp_reg);
  784.         }
  785.       else
  786.         {            /* move up to 4 bytes at a time */
  787.           move_bytes = (bytes > 4) ? 4 : bytes;
  788.           emit_insn (gen_movstrsi_1reg (dest_reg,
  789.                         src_reg,
  790.                         GEN_INT (move_bytes),
  791.                         align_rtx));
  792.         }
  793.  
  794.       if (bytes > move_bytes)
  795.         {
  796.           emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes)));
  797.           emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes)));
  798.         }
  799.     }
  800.     }
  801.  
  802.   else            /* string instructions not available */
  803.     {
  804.       num_reg = offset = 0;
  805.       for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
  806.     {
  807.       /* Calculate the correct offset for src/dest */
  808.       if (offset == 0)
  809.         {
  810.           src_addr  = src_reg;
  811.           dest_addr = dest_reg;
  812.         }
  813.       else
  814.         {
  815.           src_addr  = gen_rtx (PLUS, Pmode, src_reg,  GEN_INT (offset));
  816.           dest_addr = gen_rtx (PLUS, Pmode, dest_reg, GEN_INT (offset));
  817.         }
  818.  
  819.       /* Generate the appropriate load and store, saving the stores for later */
  820.       if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
  821.         {
  822.           move_bytes = 4;
  823.           tmp_reg = gen_reg_rtx (SImode);
  824.           emit_insn (gen_movsi (tmp_reg, gen_rtx (MEM, SImode, src_addr)));
  825.           stores[ num_reg++ ] = gen_movsi (gen_rtx (MEM, SImode, dest_addr), tmp_reg);
  826.         }
  827.       else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
  828.         {
  829.           move_bytes = 2;
  830.           tmp_reg = gen_reg_rtx (HImode);
  831.           emit_insn (gen_movhi (tmp_reg, gen_rtx (MEM, HImode, src_addr)));
  832.           stores[ num_reg++ ] = gen_movhi (gen_rtx (MEM, HImode, dest_addr), tmp_reg);
  833.         }
  834.       else
  835.         {
  836.           move_bytes = 1;
  837.           tmp_reg = gen_reg_rtx (QImode);
  838.           emit_insn (gen_movqi (tmp_reg, gen_rtx (MEM, QImode, src_addr)));
  839.           stores[ num_reg++ ] = gen_movqi (gen_rtx (MEM, QImode, dest_addr), tmp_reg);
  840.         }
  841.  
  842.       if (num_reg >= MAX_MOVE_REG)
  843.         {
  844.           for (i = 0; i < num_reg; i++)
  845.         emit_insn (stores[i]);
  846.           num_reg = 0;
  847.         }
  848.     }
  849.  
  850.       if (num_reg > 0)
  851.     {
  852.       for (i = 0; i < num_reg; i++)
  853.         emit_insn (stores[i]);
  854.     }
  855.     }
  856.  
  857.   return 1;
  858. }
  859.  
  860.  
  861. /* Return 1 if OP is a load multiple operation.  It is known to be a
  862.    PARALLEL and the first section will be tested.  */
  863.  
  864. int
  865. load_multiple_operation (op, mode)
  866.      rtx op;
  867.      enum machine_mode mode;
  868. {
  869.   int count = XVECLEN (op, 0);
  870.   int dest_regno;
  871.   rtx src_addr;
  872.   int i;
  873.  
  874.   /* Perform a quick check so we don't blow up below.  */
  875.   if (count <= 1
  876.       || GET_CODE (XVECEXP (op, 0, 0)) != SET
  877.       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
  878.       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
  879.     return 0;
  880.  
  881.   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
  882.   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
  883.  
  884.   for (i = 1; i < count; i++)
  885.     {
  886.       rtx elt = XVECEXP (op, 0, i);
  887.  
  888.       if (GET_CODE (elt) != SET
  889.       || GET_CODE (SET_DEST (elt)) != REG
  890.       || GET_MODE (SET_DEST (elt)) != SImode
  891.       || REGNO (SET_DEST (elt)) != dest_regno + i
  892.       || GET_CODE (SET_SRC (elt)) != MEM
  893.       || GET_MODE (SET_SRC (elt)) != SImode
  894.       || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
  895.       || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
  896.       || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
  897.       || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
  898.     return 0;
  899.     }
  900.  
  901.   return 1;
  902. }
  903.  
  904. /* Similar, but tests for store multiple.  Here, the second vector element
  905.    is a CLOBBER.  It will be tested later.  */
  906.  
  907. int
  908. store_multiple_operation (op, mode)
  909.      rtx op;
  910.      enum machine_mode mode;
  911. {
  912.   int count = XVECLEN (op, 0) - 1;
  913.   int src_regno;
  914.   rtx dest_addr;
  915.   int i;
  916.  
  917.   /* Perform a quick check so we don't blow up below.  */
  918.   if (count <= 1
  919.       || GET_CODE (XVECEXP (op, 0, 0)) != SET
  920.       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
  921.       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
  922.     return 0;
  923.  
  924.   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
  925.   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
  926.  
  927.   for (i = 1; i < count; i++)
  928.     {
  929.       rtx elt = XVECEXP (op, 0, i + 1);
  930.  
  931.       if (GET_CODE (elt) != SET
  932.       || GET_CODE (SET_SRC (elt)) != REG
  933.       || GET_MODE (SET_SRC (elt)) != SImode
  934.       || REGNO (SET_SRC (elt)) != src_regno + i
  935.       || GET_CODE (SET_DEST (elt)) != MEM
  936.       || GET_MODE (SET_DEST (elt)) != SImode
  937.       || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
  938.       || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
  939.       || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
  940.       || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
  941.     return 0;
  942.     }
  943.  
  944.   return 1;
  945. }
  946.  
  947. /* Return 1 if OP is a comparison operation that is valid for a branch insn.
  948.    We only check the opcode against the mode of the CC value here.  */
  949.  
  950. int
  951. branch_comparison_operator (op, mode)
  952.      register rtx op;
  953.      enum machine_mode mode;
  954. {
  955.   enum rtx_code code = GET_CODE (op);
  956.   enum machine_mode cc_mode;
  957.  
  958.   if (GET_RTX_CLASS (code) != '<')
  959.     return 0;
  960.  
  961.   cc_mode = GET_MODE (XEXP (op, 0));
  962.   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
  963.     return 0;
  964.  
  965.   if ((code == GT || code == LT || code == GE || code == LE)
  966.       && cc_mode == CCUNSmode)
  967.     return 0;
  968.  
  969.   if ((code == GTU || code == LTU || code == GEU || code == LEU)
  970.       && (cc_mode != CCUNSmode))
  971.     return 0;
  972.  
  973.   return 1;
  974. }
  975.  
  976. /* Return 1 if OP is a comparison operation that is valid for an scc insn.
  977.    We check the opcode against the mode of the CC value and disallow EQ or
  978.    NE comparisons for integers.  */
  979.  
  980. int
  981. scc_comparison_operator (op, mode)
  982.      register rtx op;
  983.      enum machine_mode mode;
  984. {
  985.   enum rtx_code code = GET_CODE (op);
  986.   enum machine_mode cc_mode;
  987.  
  988.   if (GET_MODE (op) != mode && mode != VOIDmode)
  989.     return 0;
  990.  
  991.   if (GET_RTX_CLASS (code) != '<')
  992.     return 0;
  993.  
  994.   cc_mode = GET_MODE (XEXP (op, 0));
  995.   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
  996.     return 0;
  997.  
  998.   if (code == NE && cc_mode != CCFPmode)
  999.     return 0;
  1000.  
  1001.   if ((code == GT || code == LT || code == GE || code == LE)
  1002.       && cc_mode == CCUNSmode)
  1003.     return 0;
  1004.  
  1005.   if ((code == GTU || code == LTU || code == GEU || code == LEU)
  1006.       && (cc_mode != CCUNSmode))
  1007.     return 0;
  1008.  
  1009.   if (cc_mode == CCEQmode && code != EQ && code != NE)
  1010.     return 0;
  1011.  
  1012.   return 1;
  1013. }
  1014.  
  1015. /* Return 1 if ANDOP is a mask that has no bits on that are not in the
  1016.    mask required to convert the result of a rotate insn into a shift
  1017.    left insn of SHIFTOP bits.  Both are known to be CONST_INT.  */
  1018.  
  1019. int
  1020. includes_lshift_p (shiftop, andop)
  1021.      register rtx shiftop;
  1022.      register rtx andop;
  1023. {
  1024.   int shift_mask = (~0 << INTVAL (shiftop));
  1025.  
  1026.   return (INTVAL (andop) & ~shift_mask) == 0;
  1027. }
  1028.  
  1029. /* Similar, but for right shift.  */
  1030.  
  1031. int
  1032. includes_rshift_p (shiftop, andop)
  1033.      register rtx shiftop;
  1034.      register rtx andop;
  1035. {
  1036.   unsigned shift_mask = ~0;
  1037.  
  1038.   shift_mask >>= INTVAL (shiftop);
  1039.  
  1040.   return (INTVAL (andop) & ~ shift_mask) == 0;
  1041. }
  1042.  
  1043. /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
  1044.    for lfq and stfq insns.
  1045.  
  1046.    Note reg1 and reg2 *must* be hard registers.  To be sure we will
  1047.    abort if we are passed pseudo registers.  */
  1048.  
  1049. int
  1050. registers_ok_for_quad_peep (reg1, reg2)
  1051.      rtx reg1, reg2;
  1052. {
  1053.   /* We might have been passed a SUBREG.  */
  1054.   if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) 
  1055.     return 0;
  1056.  
  1057.   return (REGNO (reg1) == REGNO (reg2) - 1);
  1058. }
  1059.  
  1060. /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.  addr1 and
  1061.    addr2 must be in consecutive memory locations (addr2 == addr1 + 8).  */
  1062.  
  1063. int
  1064. addrs_ok_for_quad_peep (addr1, addr2)
  1065.      register rtx addr1;
  1066.      register rtx addr2;
  1067. {
  1068.   int reg1;
  1069.   int offset1;
  1070.  
  1071.   /* Extract an offset (if used) from the first addr.  */
  1072.   if (GET_CODE (addr1) == PLUS)
  1073.     {
  1074.       /* If not a REG, return zero.  */
  1075.       if (GET_CODE (XEXP (addr1, 0)) != REG)
  1076.     return 0;
  1077.       else
  1078.     {
  1079.           reg1 = REGNO (XEXP (addr1, 0));
  1080.       /* The offset must be constant!  */
  1081.       if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
  1082.             return 0;
  1083.           offset1 = INTVAL (XEXP (addr1, 1));
  1084.     }
  1085.     }
  1086.   else if (GET_CODE (addr1) != REG)
  1087.     return 0;
  1088.   else
  1089.     {
  1090.       reg1 = REGNO (addr1);
  1091.       /* This was a simple (mem (reg)) expression.  Offset is 0.  */
  1092.       offset1 = 0;
  1093.     }
  1094.  
  1095.   /* Make sure the second address is a (mem (plus (reg) (const_int).  */
  1096.   if (GET_CODE (addr2) != PLUS)
  1097.     return 0;
  1098.  
  1099.   if (GET_CODE (XEXP (addr2, 0)) != REG
  1100.       || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
  1101.     return 0;
  1102.  
  1103.   if (reg1 != REGNO (XEXP (addr2, 0)))
  1104.     return 0;
  1105.  
  1106.   /* The offset for the second addr must be 8 more than the first addr.  */
  1107.   if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
  1108.     return 0;
  1109.  
  1110.   /* All the tests passed.  addr1 and addr2 are valid for lfq or stfq
  1111.      instructions.  */
  1112.   return 1;
  1113. }
  1114.  
  1115. /* Return the register class of a scratch register needed to copy IN into
  1116.    or out of a register in CLASS in MODE.  If it can be done directly,
  1117.    NO_REGS is returned.  */
  1118.  
  1119. enum reg_class
  1120. secondary_reload_class (class, mode, in)
  1121.      enum reg_class class;
  1122.      enum machine_mode mode;
  1123.      rtx in;
  1124. {
  1125.   int regno = true_regnum (in);
  1126.  
  1127.   if (regno >= FIRST_PSEUDO_REGISTER)
  1128.     regno = -1;
  1129.  
  1130.   /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
  1131.      into anything.  */
  1132.   if (class == GENERAL_REGS || class == BASE_REGS
  1133.       || (regno >= 0 && INT_REGNO_P (regno)))
  1134.     return NO_REGS;
  1135.  
  1136.   /* Constants, memory, and FP registers can go into FP registers.  */
  1137.   if ((regno == -1 || FP_REGNO_P (regno))
  1138.       && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
  1139.     return NO_REGS;
  1140.  
  1141.   /* We can copy among the CR registers.  */
  1142.   if ((class == CR_REGS || class == CR0_REGS)
  1143.       && regno >= 0 && CR_REGNO_P (regno))
  1144.     return NO_REGS;
  1145.  
  1146.   /* Otherwise, we need GENERAL_REGS.  */
  1147.   return GENERAL_REGS;
  1148. }
  1149.  
  1150. /* Given a comparison operation, return the bit number in CCR to test.  We
  1151.    know this is a valid comparison.  
  1152.  
  1153.    SCC_P is 1 if this is for an scc.  That means that %D will have been
  1154.    used instead of %C, so the bits will be in different places.
  1155.  
  1156.    Return -1 if OP isn't a valid comparison for some reason.  */
  1157.  
  1158. int
  1159. ccr_bit (op, scc_p)
  1160.      register rtx op;
  1161.      int scc_p;
  1162. {
  1163.   enum rtx_code code = GET_CODE (op);
  1164.   enum machine_mode cc_mode;
  1165.   int cc_regnum;
  1166.   int base_bit;
  1167.  
  1168.   if (GET_RTX_CLASS (code) != '<')
  1169.     return -1;
  1170.  
  1171.   cc_mode = GET_MODE (XEXP (op, 0));
  1172.   cc_regnum = REGNO (XEXP (op, 0));
  1173.   base_bit = 4 * (cc_regnum - 68);
  1174.  
  1175.   /* In CCEQmode cases we have made sure that the result is always in the
  1176.      third bit of the CR field.  */
  1177.  
  1178.   if (cc_mode == CCEQmode)
  1179.     return base_bit + 3;
  1180.  
  1181.   switch (code)
  1182.     {
  1183.     case NE:
  1184.       return scc_p ? base_bit + 3 : base_bit + 2;
  1185.     case EQ:
  1186.       return base_bit + 2;
  1187.     case GT:  case GTU:
  1188.       return base_bit + 1;
  1189.     case LT:  case LTU:
  1190.       return base_bit;
  1191.  
  1192.     case GE:  case GEU:
  1193.       /* If floating-point, we will have done a cror to put the bit in the
  1194.      unordered position.  So test that bit.  For integer, this is ! LT
  1195.      unless this is an scc insn.  */
  1196.       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
  1197.  
  1198.     case LE:  case LEU:
  1199.       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
  1200.  
  1201.     default:
  1202.       abort ();
  1203.     }
  1204. }
  1205.  
  1206. /* Print an operand.  Recognize special options, documented below.  */
  1207.  
  1208. void
  1209. print_operand (file, x, code)
  1210.     FILE *file;
  1211.     rtx x;
  1212.     char code;
  1213. {
  1214.   int i;
  1215.   int val;
  1216.  
  1217.   /* These macros test for integers and extract the low-order bits.  */
  1218. #define INT_P(X)  \
  1219. ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE)    \
  1220.  && GET_MODE (X) == VOIDmode)
  1221.  
  1222. #define INT_LOWPART(X) \
  1223.   (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
  1224.  
  1225.   switch (code)
  1226.     {
  1227.     case '.':
  1228.       /* Write out an instruction after the call which may be replaced
  1229.      with glue code by the loader.  This depends on the AIX version.  */
  1230.       asm_fprintf (file, RS6000_CALL_GLUE);
  1231.       return;
  1232.  
  1233.     case '*':
  1234.       /* Write the register number of the TOC register.  */
  1235.       fputs (TARGET_MINIMAL_TOC ? "30" : "2", file);
  1236.       return;
  1237.  
  1238.     case 'A':
  1239.       /* If X is a constant integer whose low-order 5 bits are zero,
  1240.      write 'l'.  Otherwise, write 'r'.  This is a kludge to fix a bug
  1241.      in the AIX assembler where "sri" with a zero shift count
  1242.      write a trash instruction.  */
  1243.       if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
  1244.     putc ('l', file);
  1245.       else
  1246.     putc ('r', file);
  1247.       return;
  1248.  
  1249.     case 'b':
  1250.       /* Low-order 16 bits of constant, unsigned.  */
  1251.       if (! INT_P (x))
  1252.     output_operand_lossage ("invalid %%b value");
  1253.  
  1254.       fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
  1255.       return;
  1256.  
  1257.     case 'C':
  1258.       /* This is an optional cror needed for LE or GE floating-point
  1259.      comparisons.  Otherwise write nothing.  */
  1260.       if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
  1261.       && GET_MODE (XEXP (x, 0)) == CCFPmode)
  1262.     {
  1263.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  1264.  
  1265.       fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
  1266.            base_bit + 2, base_bit + (GET_CODE (x) == GE));
  1267.     }
  1268.       return;
  1269.  
  1270.     case 'D':
  1271.       /* Similar, except that this is for an scc, so we must be able to
  1272.      encode the test in a single bit that is one.  We do the above
  1273.      for any LE, GE, GEU, or LEU and invert the bit for NE.  */
  1274.       if (GET_CODE (x) == LE || GET_CODE (x) == GE
  1275.       || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
  1276.     {
  1277.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  1278.  
  1279.       fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
  1280.            base_bit + 2,
  1281.            base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
  1282.     }
  1283.  
  1284.       else if (GET_CODE (x) == NE)
  1285.     {
  1286.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  1287.  
  1288.       fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
  1289.            base_bit + 2, base_bit + 2);
  1290.     }
  1291.       return;
  1292.  
  1293.     case 'E':
  1294.       /* X is a CR register.  Print the number of the third bit of the CR */
  1295.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  1296.     output_operand_lossage ("invalid %%E value");
  1297.  
  1298.       fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
  1299.       return;
  1300.  
  1301.     case 'f':
  1302.       /* X is a CR register.  Print the shift count needed to move it
  1303.      to the high-order four bits.  */
  1304.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  1305.     output_operand_lossage ("invalid %%f value");
  1306.       else
  1307.     fprintf (file, "%d", 4 * (REGNO (x) - 68));
  1308.       return;
  1309.  
  1310.     case 'F':
  1311.       /* Similar, but print the count for the rotate in the opposite
  1312.      direction.  */
  1313.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  1314.     output_operand_lossage ("invalid %%F value");
  1315.       else
  1316.     fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
  1317.       return;
  1318.  
  1319.     case 'G':
  1320.       /* X is a constant integer.  If it is negative, print "m",
  1321.      otherwise print "z".  This is to make a aze or ame insn.  */
  1322.       if (GET_CODE (x) != CONST_INT)
  1323.     output_operand_lossage ("invalid %%G value");
  1324.       else if (INTVAL (x) >= 0)
  1325.     putc ('z', file);
  1326.       else
  1327.     putc ('m', file);
  1328.       return;
  1329.     
  1330.     case 'h':
  1331.       /* If constant, output low-order five bits.  Otherwise,
  1332.      write normally. */
  1333.       if (INT_P (x))
  1334.     fprintf (file, "%d", INT_LOWPART (x) & 31);
  1335.       else
  1336.     print_operand (file, x, 0);
  1337.       return;
  1338.  
  1339.     case 'I':
  1340.       /* Print `i' if this is a constant, else nothing.  */
  1341.       if (INT_P (x))
  1342.     putc ('i', file);
  1343.       return;
  1344.  
  1345.     case 'j':
  1346.       /* Write the bit number in CCR for jump.  */
  1347.       i = ccr_bit (x, 0);
  1348.       if (i == -1)
  1349.     output_operand_lossage ("invalid %%j code");
  1350.       else
  1351.     fprintf (file, "%d", i);
  1352.       return;
  1353.  
  1354.     case 'J':
  1355.       /* Similar, but add one for shift count in rlinm for scc and pass
  1356.      scc flag to `ccr_bit'.  */
  1357.       i = ccr_bit (x, 1);
  1358.       if (i == -1)
  1359.     output_operand_lossage ("invalid %%J code");
  1360.       else
  1361.     /* If we want bit 31, write a shift count of zero, not 32.  */
  1362.     fprintf (file, "%d", i == 31 ? 0 : i + 1);
  1363.       return;
  1364.  
  1365.     case 'k':
  1366.       /* X must be a constant.  Write the 1's complement of the
  1367.      constant.  */
  1368.       if (! INT_P (x))
  1369.     output_operand_lossage ("invalid %%k value");
  1370.  
  1371.       fprintf (file, "%d", ~ INT_LOWPART (x));
  1372.       return;
  1373.  
  1374.     case 'L':
  1375.       /* Write second word of DImode or DFmode reference.  Works on register
  1376.      or non-indexed memory only.  */
  1377.       if (GET_CODE (x) == REG)
  1378.     fprintf (file, "%d", REGNO (x) + 1);
  1379.       else if (GET_CODE (x) == MEM)
  1380.     {
  1381.       /* Handle possible auto-increment.  Since it is pre-increment and
  1382.          we have already done it, we can just use an offset of four.  */
  1383.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  1384.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1385.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
  1386.       else
  1387.         output_address (plus_constant (XEXP (x, 0), 4));
  1388.     }
  1389.       return;
  1390.                 
  1391.     case 'm':
  1392.       /* MB value for a mask operand.  */
  1393.       if (! mask_operand (x, VOIDmode))
  1394.     output_operand_lossage ("invalid %%m value");
  1395.  
  1396.       val = INT_LOWPART (x);
  1397.  
  1398.       /* If the high bit is set and the low bit is not, the value is zero.
  1399.      If the high bit is zero, the value is the first 1 bit we find from
  1400.      the left.  */
  1401.       if (val < 0 && (val & 1) == 0)
  1402.     {
  1403.       fprintf (file, "0");
  1404.       return;
  1405.     }
  1406.       else if (val >= 0)
  1407.     {
  1408.       for (i = 1; i < 32; i++)
  1409.         if ((val <<= 1) < 0)
  1410.           break;
  1411.       fprintf (file, "%d", i);
  1412.       return;
  1413.     }
  1414.       
  1415.       /* Otherwise, look for the first 0 bit from the right.  The result is its
  1416.      number plus 1. We know the low-order bit is one.  */
  1417.       for (i = 0; i < 32; i++)
  1418.     if (((val >>= 1) & 1) == 0)
  1419.       break;
  1420.  
  1421.       /* If we ended in ...01, I would be 0.  The correct value is 31, so
  1422.      we want 31 - i.  */
  1423.       fprintf (file, "%d", 31 - i);
  1424.       return;
  1425.  
  1426.     case 'M':
  1427.       /* ME value for a mask operand.  */
  1428.       if (! mask_operand (x, VOIDmode))
  1429.     output_operand_lossage ("invalid %%m value");
  1430.  
  1431.       val = INT_LOWPART (x);
  1432.  
  1433.       /* If the low bit is set and the high bit is not, the value is 31.
  1434.      If the low bit is zero, the value is the first 1 bit we find from
  1435.      the right.  */
  1436.       if ((val & 1) && val >= 0)
  1437.     {
  1438.       fputs ("31", file);
  1439.       return;
  1440.     }
  1441.       else if ((val & 1) == 0)
  1442.     {
  1443.       for (i = 0; i < 32; i++)
  1444.         if ((val >>= 1) & 1)
  1445.           break;
  1446.  
  1447.       /* If we had ....10, I would be 0.  The result should be
  1448.          30, so we need 30 - i.  */
  1449.       fprintf (file, "%d", 30 - i);
  1450.       return;
  1451.     }
  1452.       
  1453.       /* Otherwise, look for the first 0 bit from the left.  The result is its
  1454.      number minus 1. We know the high-order bit is one.  */
  1455.       for (i = 0; i < 32; i++)
  1456.     if ((val <<= 1) >= 0)
  1457.       break;
  1458.  
  1459.       fprintf (file, "%d", i);
  1460.       return;
  1461.  
  1462.     case 'N':
  1463.       /* Write the number of elements in the vector times 4.  */
  1464.       if (GET_CODE (x) != PARALLEL)
  1465.     output_operand_lossage ("invalid %%N value");
  1466.  
  1467.       fprintf (file, "%d", XVECLEN (x, 0) * 4);
  1468.       return;
  1469.  
  1470.     case 'O':
  1471.       /* Similar, but subtract 1 first.  */
  1472.       if (GET_CODE (x) != PARALLEL)
  1473.     output_operand_lossage ("invalid %%N value");
  1474.  
  1475.       fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
  1476.       return;
  1477.  
  1478.     case 'p':
  1479.       /* X is a CONST_INT that is a power of two.  Output the logarithm.  */
  1480.       if (! INT_P (x)
  1481.       || (i = exact_log2 (INT_LOWPART (x))) < 0)
  1482.     output_operand_lossage ("invalid %%p value");
  1483.  
  1484.       fprintf (file, "%d", i);
  1485.       return;
  1486.  
  1487.     case 'P':
  1488.       /* The operand must be an indirect memory reference.  The result
  1489.      is the register number. */
  1490.       if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
  1491.       || REGNO (XEXP (x, 0)) >= 32)
  1492.     output_operand_lossage ("invalid %%P value");
  1493.  
  1494.       fprintf (file, "%d", REGNO (XEXP (x, 0)));
  1495.       return;
  1496.  
  1497.     case 'R':
  1498.       /* X is a CR register.  Print the mask for `mtcrf'.  */
  1499.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  1500.     output_operand_lossage ("invalid %%R value");
  1501.       else
  1502.     fprintf (file, "%d", 128 >> (REGNO (x) - 68));
  1503.       return;
  1504.  
  1505.     case 's':
  1506.       /* Low 5 bits of 32 - value */
  1507.       if (! INT_P (x))
  1508.     output_operand_lossage ("invalid %%s value");
  1509.  
  1510.       fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
  1511.       return;
  1512.  
  1513.     case 't':
  1514.       /* Write 12 if this jump operation will branch if true, 4 otherwise. 
  1515.      All floating-point operations except NE branch true and integer
  1516.      EQ, LT, GT, LTU and GTU also branch true.  */
  1517.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1518.     output_operand_lossage ("invalid %%t value");
  1519.  
  1520.       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
  1521.         && GET_CODE (x) != NE)
  1522.            || GET_CODE (x) == EQ
  1523.            || GET_CODE (x) == LT || GET_CODE (x) == GT
  1524.            || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
  1525.     fputs ("12", file);
  1526.       else
  1527.     putc ('4', file);
  1528.       return;
  1529.       
  1530.     case 'T':
  1531.       /* Opposite of 't': write 4 if this jump operation will branch if true,
  1532.      12 otherwise.   */
  1533.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1534.     output_operand_lossage ("invalid %%t value");
  1535.  
  1536.       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
  1537.         && GET_CODE (x) != NE)
  1538.            || GET_CODE (x) == EQ
  1539.            || GET_CODE (x) == LT || GET_CODE (x) == GT
  1540.            || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
  1541.     putc ('4', file);
  1542.       else
  1543.     fputs ("12", file);
  1544.       return;
  1545.       
  1546.     case 'u':
  1547.       /* High-order 16 bits of constant.  */
  1548.       if (! INT_P (x))
  1549.     output_operand_lossage ("invalid %%u value");
  1550.  
  1551.       fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
  1552.       return;
  1553.  
  1554.     case 'U':
  1555.       /* Print `u' if this has an auto-increment or auto-decrement.  */
  1556.       if (GET_CODE (x) == MEM
  1557.       && (GET_CODE (XEXP (x, 0)) == PRE_INC
  1558.           || GET_CODE (XEXP (x, 0)) == PRE_DEC))
  1559.     putc ('u', file);
  1560.       return;
  1561.  
  1562.     case 'w':
  1563.       /* If constant, low-order 16 bits of constant, signed.  Otherwise, write
  1564.      normally.  */
  1565.       if (INT_P (x))
  1566.     fprintf (file, "%d",
  1567.          (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
  1568.       else
  1569.     print_operand (file, x, 0);
  1570.       return;
  1571.  
  1572.     case 'W':
  1573.       /* If constant, low-order 16 bits of constant, unsigned.
  1574.      Otherwise, write normally.  */
  1575.       if (INT_P (x))
  1576.     fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
  1577.       else
  1578.     print_operand (file, x, 0);
  1579.       return;
  1580.  
  1581.     case 'X':
  1582.       if (GET_CODE (x) == MEM
  1583.       && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
  1584.     putc ('x', file);
  1585.       return;
  1586.  
  1587.     case 'Y':
  1588.       /* Like 'L', for third word of TImode  */
  1589.       if (GET_CODE (x) == REG)
  1590.     fprintf (file, "%d", REGNO (x) + 2);
  1591.       else if (GET_CODE (x) == MEM)
  1592.     {
  1593.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  1594.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1595.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
  1596.       else
  1597.         output_address (plus_constant (XEXP (x, 0), 8));
  1598.     }
  1599.       return;
  1600.                 
  1601.     case 'z':
  1602.       /* X is a SYMBOL_REF.  Write out the name preceded by a
  1603.      period and without any trailing data in brackets.  Used for function
  1604.      names.  If we are configured for System V (or the embedded ABI) on
  1605.      the PowerPC, do not emit the period, since those systems do not use
  1606.      TOCs and the like.  */
  1607.       if (GET_CODE (x) != SYMBOL_REF)
  1608.     abort ();
  1609.  
  1610. #ifndef USING_SVR4_H
  1611.       putc ('.', file);
  1612. #endif
  1613.       RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
  1614.       return;
  1615.  
  1616.     case 'Z':
  1617.       /* Like 'L', for last word of TImode.  */
  1618.       if (GET_CODE (x) == REG)
  1619.     fprintf (file, "%d", REGNO (x) + 3);
  1620.       else if (GET_CODE (x) == MEM)
  1621.     {
  1622.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  1623.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1624.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
  1625.       else
  1626.         output_address (plus_constant (XEXP (x, 0), 12));
  1627.     }
  1628.       return;
  1629.                 
  1630.     case 0:
  1631.       if (GET_CODE (x) == REG)
  1632.     fprintf (file, "%s", reg_names[REGNO (x)]);
  1633.       else if (GET_CODE (x) == MEM)
  1634.     {
  1635.       /* We need to handle PRE_INC and PRE_DEC here, since we need to
  1636.          know the width from the mode.  */
  1637.       if (GET_CODE (XEXP (x, 0)) == PRE_INC)
  1638.         fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
  1639.              REGNO (XEXP (XEXP (x, 0), 0)));
  1640.       else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1641.         fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
  1642.              REGNO (XEXP (XEXP (x, 0), 0)));
  1643.       else
  1644.         output_address (XEXP (x, 0));
  1645.     }
  1646.       else
  1647.     output_addr_const (file, x);
  1648.       return;
  1649.  
  1650.     default:
  1651.       output_operand_lossage ("invalid %%xn code");
  1652.     }
  1653. }
  1654.  
  1655. /* Print the address of an operand.  */
  1656.  
  1657. void
  1658. print_operand_address (file, x)
  1659.      FILE *file;
  1660.      register rtx x;
  1661. {
  1662.   if (GET_CODE (x) == REG)
  1663.     fprintf (file, "0(%d)", REGNO (x));
  1664.   else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
  1665.     {
  1666.       output_addr_const (file, x);
  1667.       /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
  1668.      of the toc pointer.  */
  1669.       if (TARGET_MINIMAL_TOC)
  1670.     fprintf (file, "(30)");
  1671.       else
  1672.     fprintf (file, "(2)");
  1673.     }
  1674.   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
  1675.     {
  1676.       if (REGNO (XEXP (x, 0)) == 0)
  1677.     fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0)));
  1678.       else
  1679.     fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1)));
  1680.     }
  1681.   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
  1682.     fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0)));
  1683.   else
  1684.     abort ();
  1685. }
  1686.  
  1687. /* This page contains routines that are used to determine what the function
  1688.    prologue and epilogue code will do and write them out.  */
  1689.  
  1690. /*  Return the first fixed-point register that is required to be saved. 32 if
  1691.     none.  */
  1692.  
  1693. int
  1694. first_reg_to_save ()
  1695. {
  1696.   int first_reg;
  1697.  
  1698.   /* Find lowest numbered live register.  */
  1699.   for (first_reg = 13; first_reg <= 31; first_reg++)
  1700.     if (regs_ever_live[first_reg])
  1701.       break;
  1702.  
  1703.   /* If profiling, then we must save/restore every register that contains
  1704.      a parameter before/after the .mcount call.  Use registers from 30 down
  1705.      to 23 to do this.  Don't use the frame pointer in reg 31.
  1706.  
  1707.      For now, save enough room for all of the parameter registers.  */
  1708.   if (profile_flag)
  1709.     if (first_reg > 23)
  1710.       first_reg = 23;
  1711.  
  1712.   return first_reg;
  1713. }
  1714.  
  1715. /* Similar, for FP regs.  */
  1716.  
  1717. int
  1718. first_fp_reg_to_save ()
  1719. {
  1720.   int first_reg;
  1721.  
  1722.   /* Find lowest numbered live register.  */
  1723.   for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
  1724.     if (regs_ever_live[first_reg])
  1725.       break;
  1726.  
  1727.   return first_reg;
  1728. }
  1729.  
  1730. /* Return 1 if we need to save CR.  */
  1731.  
  1732. int
  1733. must_save_cr ()
  1734. {
  1735.   return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72];
  1736. }
  1737.  
  1738. /* Compute the size of the save area in the stack, including the space for
  1739.    the fixed area.  */
  1740.  
  1741. int
  1742. rs6000_sa_size ()
  1743. {
  1744.   int size;
  1745.  
  1746.   /* We have the six fixed words, plus the size of the register save 
  1747.      areas, rounded to a double-word.  */
  1748.   size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2;
  1749.   if (size & 1)
  1750.     size++;
  1751.  
  1752.   return size * 4;
  1753. }
  1754.  
  1755. /* Return non-zero if this function makes calls.  */
  1756.  
  1757. int
  1758. rs6000_makes_calls ()
  1759. {
  1760.   rtx insn;
  1761.  
  1762.   /* If we are profiling, we will be making a call to mcount.  */
  1763.   if (profile_flag)
  1764.     return 1;
  1765.  
  1766.   for (insn = get_insns (); insn; insn = next_insn (insn))
  1767.     if (GET_CODE (insn) == CALL_INSN)
  1768.       return 1;
  1769.  
  1770.   return 0;
  1771. }
  1772.  
  1773. /* Return non-zero if this function needs to push space on the stack.  */
  1774.  
  1775. int
  1776. rs6000_pushes_stack ()
  1777. {
  1778.   int total_size = (rs6000_sa_size () + get_frame_size ()
  1779.             + current_function_outgoing_args_size);
  1780.  
  1781.   /* We need to push the stack if a frame pointer is needed (because the
  1782.      stack might be dynamically adjusted), if we are debugging, if the
  1783.      total stack size is more than 220 bytes, or if we make calls.  */
  1784.  
  1785.   return (frame_pointer_needed || write_symbols != NO_DEBUG
  1786.       || total_size > 220
  1787.       || rs6000_makes_calls ());
  1788. }
  1789.  
  1790. #ifdef USING_SVR4_H
  1791. /* Write out a System V.4 style traceback table before the prologue
  1792.  
  1793.    At present, only emit the basic tag table (ie, do not emit tag_types other
  1794.    than 0, which might use more than 1 tag word).
  1795.  
  1796.    The first tag word looks like:
  1797.  
  1798.     0            1            2            3
  1799.     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  1800.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1801.    |         0 |ver| tag |e|s| alloca  | # fprs  | # gprs  |s|l|c|f|
  1802.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1803.  
  1804. */
  1805.  
  1806. void
  1807. svr4_traceback (file, name, decl)
  1808.      FILE *file;
  1809.      tree name, decl;
  1810. {
  1811.  
  1812.   int first_reg        = first_reg_to_save ();
  1813.   int first_fp_reg    = first_fp_reg_to_save ();
  1814.   int pushes_stack    = rs6000_pushes_stack ();
  1815.   long tag;
  1816.   long version        = 0;            /* version number */
  1817.   long tag_type        = 0;            /* function type */
  1818.   long extended_tag    = 0;            /* additional tag words needed */
  1819.   long spare        = 0;            /* reserved for future use */
  1820.   long alloca_reg;                /* stack/frame register */
  1821.   long fpr_max        = 64 - first_fp_reg;    /* # of floating point registers saved */
  1822.   long gpr_max        = 32 - first_reg;    /* # of general purpose registers saved */
  1823.   long sp_max;                    /* 1 if the function acquires a stack frame */
  1824.   long lr_max;                    /* 1 if the function stores the link register */
  1825.   long cr_max;                    /* 1 if the function has a CR save word */
  1826.   long fpscr_max    = 0;            /* 1 if the function has a FPSCR save word */
  1827.  
  1828.   if (frame_pointer_needed)
  1829.     alloca_reg = 31;
  1830.  
  1831.   else if (pushes_stack != 0)
  1832.     alloca_reg = 1;
  1833.  
  1834.   else
  1835.     alloca_reg = 0;
  1836.  
  1837.   lr_max = (regs_ever_live[65] || first_fp_reg < 62 || profile_flag);
  1838.   cr_max = (must_save_cr () != 0);
  1839.   sp_max = (pushes_stack != 0);
  1840.  
  1841.   tag = (((version & 3) << 24)
  1842.      | ((tag_type & 7) << 21)
  1843.      | ((extended_tag & 1) << 20)
  1844.      | ((spare & 1) << 19)
  1845.      | ((alloca_reg & 0x1f) << 14)
  1846.      | ((fpr_max & 0x1f) << 9)
  1847.      | ((gpr_max & 0x1f) << 4)
  1848.      | ((sp_max & 1) << 3)
  1849.      | ((lr_max & 1) << 2)
  1850.      | ((cr_max & 1) << 1)
  1851.      | ((fpscr_max & 1) << 0));
  1852.        
  1853.   fprintf (file, "\t.long 0x%lx\n", tag);
  1854. }
  1855.  
  1856. #endif /* USING_SVR4_H */
  1857.  
  1858. /* Write function prologue.  */
  1859.  
  1860. void
  1861. output_prolog (file, size)
  1862.      FILE *file;
  1863.      int size;
  1864. {
  1865.   int first_reg = first_reg_to_save ();
  1866.   int must_push = rs6000_pushes_stack ();
  1867.   int first_fp_reg = first_fp_reg_to_save ();
  1868.   int basic_size = rs6000_sa_size ();
  1869.   int total_size = (basic_size + size + current_function_outgoing_args_size);
  1870.   char buf[256];
  1871.  
  1872.   /* Round size to multiple of 8 bytes.  */
  1873.   total_size = (total_size + 7) & ~7;
  1874.  
  1875.   /* Write .extern for any function we will call to save and restore fp
  1876.      values.  */
  1877. #ifndef USING_SVR4_H
  1878.   if (first_fp_reg < 62)
  1879.     fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
  1880.          SAVE_FP_PREFIX, first_fp_reg - 32, SAVE_FP_SUFFIX,
  1881.          RESTORE_FP_PREFIX, first_fp_reg - 32, RESTORE_FP_SUFFIX);
  1882. #endif
  1883.  
  1884.   /* Write .extern for truncation routines, if needed.  */
  1885.   if (rs6000_trunc_used && ! trunc_defined)
  1886.     {
  1887.       fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
  1888.            RS6000_ITRUNC, RS6000_UITRUNC);
  1889.       trunc_defined = 1;
  1890.     }
  1891.   /* Write .extern for AIX common mode routines, if needed.  */
  1892.   if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
  1893.     {
  1894.       fputs ("\t.extern __mulh\n", file);
  1895.       fputs ("\t.extern __mull\n", file);
  1896.       fputs ("\t.extern __divss\n", file);
  1897.       fputs ("\t.extern __divus\n", file);
  1898.       fputs ("\t.extern __quoss\n", file);
  1899.       fputs ("\t.extern __quous\n", file);
  1900.       common_mode_defined = 1;
  1901.     }
  1902.  
  1903. #ifdef USING_SVR4_H
  1904.   /* If we have a relocatable GOT section, we need to save the LR. */
  1905.   if (TARGET_RELOCATABLE && get_pool_size () != 0)
  1906.     regs_ever_live[65] = 1;
  1907. #endif
  1908.  
  1909.   /* If we have to call a function to save fpr's, or if we are doing profiling,
  1910.      then we will be using LR.  */
  1911.   if (profile_flag)
  1912.     regs_ever_live[65] = 1;
  1913.  
  1914. #ifndef USING_SVR4_H
  1915.   if (first_fp_reg < 62)
  1916.     regs_ever_live[65] = 1;
  1917. #endif
  1918.  
  1919.   /* If we use the link register, get it into r0.  */
  1920.   if (regs_ever_live[65])
  1921.     asm_fprintf (file, "\tmflr 0\n");
  1922.  
  1923.   /* If we need to save CR, put it into r12.  */
  1924.   if (must_save_cr ())
  1925.     asm_fprintf (file, "\tmfcr 12\n");
  1926.  
  1927.   /* Do any required saving of fpr's.  If only one or two to save, do it
  1928.      ourself.  Otherwise, call function.  Note that since they are statically
  1929.      linked, we do not need a nop following them.  */
  1930.   if (first_fp_reg == 62)
  1931.     asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n");
  1932.   else if (first_fp_reg == 63)
  1933.     asm_fprintf (file, "\tstfd 31,-8(1)\n");
  1934.   else if (first_fp_reg != 64)
  1935.     {
  1936. #ifndef USING_SVR4_H
  1937.       asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX, first_fp_reg - 32, SAVE_FP_SUFFIX);
  1938. #else
  1939.       int regno, loc;
  1940.  
  1941.       for (regno = first_fp_reg,
  1942.        loc = - (64 - first_fp_reg) * 8;
  1943.        regno < 64;
  1944.        regno++, loc += 8)
  1945.     asm_fprintf (file, "\tstfd %d,%d(1)\n", regno - 32, loc);
  1946. #endif
  1947.     }
  1948.  
  1949.   /* Now save gpr's.  */
  1950.   if (! TARGET_MULTIPLE || first_reg == 31)
  1951.     {
  1952.       int regno, loc;
  1953.  
  1954.       for (regno = first_reg,
  1955.        loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
  1956.        regno < 32;
  1957.        regno++, loc += 4)
  1958.     asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc);
  1959.     }
  1960.  
  1961.   else if (first_reg != 32)
  1962.     asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg,
  1963.          - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
  1964.  
  1965.   /* Save lr if we used it.  */
  1966.   if (regs_ever_live[65])
  1967.     asm_fprintf (file, "\t{st|stw} 0,8(1)\n");
  1968.  
  1969.   /* Save CR if we use any that must be preserved.  */
  1970.   if (must_save_cr ())
  1971.     asm_fprintf (file, "\t{st|stw} 12,4(1)\n");
  1972.  
  1973.   /* Update stack and set back pointer.  */
  1974.   if (must_push)
  1975.     {
  1976.       if (total_size < 32767)
  1977.     asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size);
  1978.       else
  1979.     {
  1980.       asm_fprintf (file, "\t{liu|lis} 0,%d\n\t{oril|ori} 0,0,%d\n",
  1981.            (total_size >> 16) & 0xffff, total_size & 0xffff);
  1982.       if (TARGET_POWERPC)
  1983.         asm_fprintf (file, "\tsubf 12,0,1\n");
  1984.       else
  1985.         asm_fprintf (file, "\t{sf|subfc} 12,0,1\n");
  1986.       asm_fprintf (file, "\t{st|stw} 1,0(12)\n\tmr 1,12\n");
  1987.     }
  1988.     }
  1989.  
  1990.   /* Set frame pointer, if needed.  */
  1991.   if (frame_pointer_needed)
  1992.     asm_fprintf (file, "\tmr 31,1\n");
  1993.  
  1994.   /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
  1995.      TOC_TABLE address into register 30.  */
  1996.   if (TARGET_MINIMAL_TOC && get_pool_size () != 0)
  1997.     {
  1998.       char buf[256];
  1999.  
  2000. #ifdef USING_SVR4_H
  2001.       if (TARGET_RELOCATABLE)
  2002.     {
  2003.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
  2004.       fprintf (file, "\tbl ");
  2005.       assemble_name (file, buf);
  2006.       fprintf (file, "\n");
  2007.  
  2008.       ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
  2009.       fprintf (file, "\tmflr 30\n");
  2010.  
  2011.       if (TARGET_POWERPC64)
  2012.         fprintf (file, "\tld 0,");
  2013.       else if (TARGET_NEW_MNEMONICS)
  2014.         fprintf (file, "\tlwz 0,");
  2015.       else
  2016.         fprintf (file, "\tl 0,");
  2017.  
  2018.       fprintf (file, "(");
  2019.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
  2020.       assemble_name (file, buf);
  2021.       fprintf (file, "-");
  2022.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
  2023.       assemble_name (file, buf);
  2024.       fprintf (file, ")(30)\n");
  2025.       asm_fprintf (file, "\t{cax|add} 30,0,30\n");
  2026.       rs6000_pic_labelno++;
  2027.     }
  2028.       else if (TARGET_NO_TOC)
  2029.     {
  2030.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
  2031.       asm_fprintf (file, "\t{cau|addis} 30,0,");
  2032.       assemble_name (file, buf);
  2033.       asm_fprintf (file, "@ha\n");
  2034.       asm_fprintf (file, "\t{cal|addi} 30,30,");
  2035.       assemble_name (file, buf);
  2036.       asm_fprintf (file, "@l\n");
  2037.     }
  2038.       else
  2039. #endif /* USING_SVR4_H */
  2040.     {
  2041.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
  2042.       asm_fprintf (file, "\t{l|lwz} 30,");
  2043.       assemble_name (file, buf);
  2044.       asm_fprintf (file, "(2)\n");
  2045.     }
  2046.     }
  2047. }
  2048.  
  2049. /* Write function epilogue.  */
  2050.  
  2051. void
  2052. output_epilog (file, size)
  2053.      FILE *file;
  2054.      int size;
  2055. {
  2056.   int first_reg = first_reg_to_save ();
  2057.   int must_push = rs6000_pushes_stack ();
  2058.   int first_fp_reg = first_fp_reg_to_save ();
  2059.   int basic_size = rs6000_sa_size ();
  2060.   int total_size = (basic_size + size + current_function_outgoing_args_size);
  2061.   rtx insn = get_last_insn ();
  2062.  
  2063.   /* Round size to multiple of 8 bytes.  */
  2064.   total_size = (total_size + 7) & ~7;
  2065.  
  2066.   /* If the last insn was a BARRIER, we don't have to write anything except
  2067.      the trace table.  */
  2068.   if (GET_CODE (insn) == NOTE)
  2069.     insn = prev_nonnote_insn (insn);
  2070.   if (insn == 0 ||  GET_CODE (insn) != BARRIER)
  2071.     {
  2072.       /* If we have a frame pointer, a call to alloca,  or a large stack
  2073.      frame, restore the old stack pointer using the backchain.  Otherwise,
  2074.      we know what size to update it with.  */
  2075.       if (frame_pointer_needed || current_function_calls_alloca
  2076.       || total_size > 32767)
  2077.     asm_fprintf (file, "\t{l|lwz} 1,0(1)\n");
  2078.       else if (must_push)
  2079.     asm_fprintf (file, "\t{cal 1,%d(1)|addi 1,1,%d}\n", total_size);
  2080.  
  2081.       /* Get the old lr if we saved it.  */
  2082.       if (regs_ever_live[65])
  2083.     asm_fprintf (file, "\t{l|lwz} 0,8(1)\n");
  2084.  
  2085.       /* Get the old cr if we saved it.  */
  2086.       if (must_save_cr ())
  2087.     asm_fprintf (file, "\t{l|lwz} 12,4(1)\n");
  2088.  
  2089.       /* Set LR here to try to overlap restores below.  */
  2090.       if (regs_ever_live[65])
  2091.     asm_fprintf (file, "\tmtlr 0\n");
  2092.  
  2093.       /* Restore gpr's.  */
  2094.       if (! TARGET_MULTIPLE || first_reg == 31)
  2095.     {
  2096.       int regno, loc;
  2097.  
  2098.       for (regno = first_reg,
  2099.            loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
  2100.            regno < 32;
  2101.            regno++, loc += 4)
  2102.         asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc);
  2103.     }
  2104.  
  2105.       else if (first_reg != 32)
  2106.     asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg,
  2107.          - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
  2108.  
  2109.       /* Restore fpr's if we can do it without calling a function.  */
  2110.       if (first_fp_reg == 62)
  2111.     asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n");
  2112.       else if (first_fp_reg == 63)
  2113.     asm_fprintf (file, "\tlfd 31,-8(1)\n");
  2114.  
  2115.       /* If we saved cr, restore it here.  Just those of cr2, cr3, and cr4
  2116.      that were used.  */
  2117.       if (must_save_cr ())
  2118.     asm_fprintf (file, "\tmtcrf %d,12\n",
  2119.              (regs_ever_live[70] != 0) * 0x20
  2120.              + (regs_ever_live[71] != 0) * 0x10
  2121.              + (regs_ever_live[72] != 0) * 0x8);
  2122.  
  2123.       /* If we have to restore more than two FP registers, branch to the
  2124.      restore function.  It will return to our caller.  */
  2125.       if (first_fp_reg < 62)
  2126.     {
  2127. #ifndef USING_SVR4_H
  2128.       asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX, first_fp_reg - 32, RESTORE_FP_SUFFIX);
  2129. #else
  2130.       int regno, loc;
  2131.  
  2132.       for (regno = first_fp_reg,
  2133.            loc = - (64 - first_fp_reg) * 8;
  2134.            regno < 64;
  2135.            regno++, loc += 8)
  2136.         asm_fprintf (file, "\tlfd %d,%d(1)\n", regno - 32, loc);
  2137.  
  2138.       asm_fprintf (file, "\t{br|blr}\n");
  2139. #endif
  2140.     }
  2141.       else
  2142.     asm_fprintf (file, "\t{br|blr}\n");
  2143.     }
  2144.  
  2145.   /* Output a traceback table here.  See /usr/include/sys/debug.h for info
  2146.      on its format.
  2147.  
  2148.      We don't output a traceback table if -finhibit-size-directive was
  2149.      used.  The documentation for -finhibit-size-directive reads
  2150.      ``don't output a @code{.size} assembler directive, or anything
  2151.      else that would cause trouble if the function is split in the
  2152.      middle, and the two halves are placed at locations far apart in
  2153.      memory.''  The traceback table has this property, since it
  2154.      includes the offset from the start of the function to the
  2155.      traceback table itself.
  2156.  
  2157.      System V.4 Powerpc's (and the embedded ABI derived from it) use a
  2158.      different traceback table located before the prologue.  */
  2159. #ifndef USING_SVR4_H
  2160.   if (! flag_inhibit_size_directive)
  2161.     {
  2162.       char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
  2163.       int fixed_parms, float_parms, parm_info;
  2164.       int i;
  2165.  
  2166.       /* Need label immediately before tbtab, so we can compute its offset
  2167.      from the function start.  */
  2168.       if (*fname == '*')
  2169.     ++fname;
  2170.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
  2171.       ASM_OUTPUT_LABEL (file, fname);
  2172.  
  2173.       /* The .tbtab pseudo-op can only be used for the first eight
  2174.      expressions, since it can't handle the possibly variable
  2175.      length fields that follow.  However, if you omit the optional
  2176.      fields, the assembler outputs zeros for all optional fields
  2177.      anyways, giving each variable length field is minimum length
  2178.      (as defined in sys/debug.h).  Thus we can not use the .tbtab
  2179.      pseudo-op at all.  */
  2180.  
  2181.       /* An all-zero word flags the start of the tbtab, for debuggers
  2182.      that have to find it by searching forward from the entry
  2183.      point or from the current pc.  */
  2184.       fprintf (file, "\t.long 0\n");
  2185.  
  2186.       /* Tbtab format type.  Use format type 0.  */
  2187.       fprintf (file, "\t.byte 0,");
  2188.  
  2189.       /* Language type.  Unfortunately, there doesn't seem to be any
  2190.      official way to get this info, so we use language_string.  C
  2191.      is 0.  C++ is 9.  No number defined for Obj-C, so use the
  2192.      value for C for now.  */
  2193.       if (! strcmp (language_string, "GNU C")
  2194.       || ! strcmp (language_string, "GNU Obj-C"))
  2195.     i = 0;
  2196.       else if (! strcmp (language_string, "GNU F77"))
  2197.     i = 1;
  2198.       else if (! strcmp (language_string, "GNU Ada"))
  2199.     i = 3;
  2200.       else if (! strcmp (language_string, "GNU PASCAL"))
  2201.     i = 2;
  2202.       else if (! strcmp (language_string, "GNU C++"))
  2203.     i = 9;
  2204.       else
  2205.     abort ();
  2206.       fprintf (file, "%d,", i);
  2207.  
  2208.       /* 8 single bit fields: global linkage (not set for C extern linkage,
  2209.      apparently a PL/I convention?), out-of-line epilogue/prologue, offset
  2210.      from start of procedure stored in tbtab, internal function, function
  2211.      has controlled storage, function has no toc, function uses fp,
  2212.      function logs/aborts fp operations.  */
  2213.       /* Assume that fp operations are used if any fp reg must be saved.  */
  2214.       fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1));
  2215.  
  2216.       /* 6 bitfields: function is interrupt handler, name present in
  2217.      proc table, function calls alloca, on condition directives
  2218.      (controls stack walks, 3 bits), saves condition reg, saves
  2219.      link reg.  */
  2220.       /* The `function calls alloca' bit seems to be set whenever reg 31 is
  2221.      set up as a frame pointer, even when there is no alloca call.  */
  2222.       fprintf (file, "%d,",
  2223.            ((1 << 6) | (frame_pointer_needed << 5)
  2224.         | (must_save_cr () << 1) | (regs_ever_live[65])));
  2225.  
  2226.       /* 3 bitfields: saves backchain, spare bit, number of fpr saved
  2227.      (6 bits).  */
  2228.       fprintf (file, "%d,",
  2229.            (must_push << 7) | (64 - first_fp_reg_to_save ()));
  2230.  
  2231.       /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits).  */
  2232.       fprintf (file, "%d,", (32 - first_reg_to_save ()));
  2233.  
  2234.       {
  2235.     /* Compute the parameter info from the function decl argument
  2236.        list.  */
  2237.     tree decl;
  2238.     int next_parm_info_bit;
  2239.  
  2240.     next_parm_info_bit = 31;
  2241.     parm_info = 0;
  2242.     fixed_parms = 0;
  2243.     float_parms = 0;
  2244.  
  2245.     for (decl = DECL_ARGUMENTS (current_function_decl);
  2246.          decl; decl = TREE_CHAIN (decl))
  2247.       {
  2248.         rtx parameter = DECL_INCOMING_RTL (decl);
  2249.         enum machine_mode mode = GET_MODE (parameter);
  2250.  
  2251.         if (GET_CODE (parameter) == REG)
  2252.           {
  2253.         if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  2254.           {
  2255.             int bits;
  2256.  
  2257.             float_parms++;
  2258.  
  2259.             if (mode == SFmode)
  2260.               bits = 0x2;
  2261.             else if (mode == DFmode)
  2262.               bits = 0x3;
  2263.             else
  2264.               abort ();
  2265.  
  2266.             /* If only one bit will fit, don't or in this entry.  */
  2267.             if (next_parm_info_bit > 0)
  2268.               parm_info |= (bits << (next_parm_info_bit - 1));
  2269.             next_parm_info_bit -= 2;
  2270.           }
  2271.         else
  2272.           {
  2273.             fixed_parms += ((GET_MODE_SIZE (mode)
  2274.                      + (UNITS_PER_WORD - 1))
  2275.                     / UNITS_PER_WORD);
  2276.             next_parm_info_bit -= 1;
  2277.           }
  2278.           }
  2279.       }
  2280.       }
  2281.  
  2282.       /* Number of fixed point parameters.  */
  2283.       /* This is actually the number of words of fixed point parameters; thus
  2284.      an 8 byte struct counts as 2; and thus the maximum value is 8.  */
  2285.       fprintf (file, "%d,", fixed_parms);
  2286.  
  2287.       /* 2 bitfields: number of floating point parameters (7 bits), parameters
  2288.      all on stack.  */
  2289.       /* This is actually the number of fp registers that hold parameters;
  2290.      and thus the maximum value is 13.  */
  2291.       /* Set parameters on stack bit if parameters are not in their original
  2292.      registers, regardless of whether they are on the stack?  Xlc
  2293.      seems to set the bit when not optimizing.  */
  2294.       fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
  2295.  
  2296.       /* Optional fields follow.  Some are variable length.  */
  2297.  
  2298.       /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
  2299.      11 double float.  */
  2300.       /* There is an entry for each parameter in a register, in the order that
  2301.      they occur in the parameter list.  Any intervening arguments on the
  2302.      stack are ignored.  If the list overflows a long (max possible length
  2303.      34 bits) then completely leave off all elements that don't fit.  */
  2304.       /* Only emit this long if there was at least one parameter.  */
  2305.       if (fixed_parms || float_parms)
  2306.     fprintf (file, "\t.long %d\n", parm_info);
  2307.  
  2308.       /* Offset from start of code to tb table.  */
  2309.       fprintf (file, "\t.long ");
  2310.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
  2311.       RS6000_OUTPUT_BASENAME (file, fname);
  2312.       fprintf (file, "-.");
  2313.       RS6000_OUTPUT_BASENAME (file, fname);
  2314.       fprintf (file, "\n");
  2315.  
  2316.       /* Interrupt handler mask.  */
  2317.       /* Omit this long, since we never set the interrupt handler bit
  2318.      above.  */
  2319.  
  2320.       /* Number of CTL (controlled storage) anchors.  */
  2321.       /* Omit this long, since the has_ctl bit is never set above.  */
  2322.  
  2323.       /* Displacement into stack of each CTL anchor.  */
  2324.       /* Omit this list of longs, because there are no CTL anchors.  */
  2325.  
  2326.       /* Length of function name.  */
  2327.       fprintf (file, "\t.short %d\n", strlen (fname));
  2328.  
  2329.       /* Function name.  */
  2330.       assemble_string (fname, strlen (fname));
  2331.  
  2332.       /* Register for alloca automatic storage; this is always reg 31.
  2333.      Only emit this if the alloca bit was set above.  */
  2334.       if (frame_pointer_needed)
  2335.     fprintf (file, "\t.byte 31\n");
  2336.     }
  2337. #endif /* !USING_SVR4_H */
  2338. }
  2339.  
  2340. /* Output a TOC entry.  We derive the entry name from what is
  2341.    being written.  */
  2342.  
  2343. void
  2344. output_toc (file, x, labelno)
  2345.      FILE *file;
  2346.      rtx x;
  2347.      int labelno;
  2348. {
  2349.   char buf[256];
  2350.   char *name = buf;
  2351.   rtx base = x;
  2352.   int offset = 0;
  2353.  
  2354. #ifdef USING_SVR4_H
  2355.   if (TARGET_MINIMAL_TOC)
  2356.     {
  2357.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
  2358.       fprintf (file, "%d = .-", labelno);
  2359.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
  2360.       fprintf (file, "1\n");
  2361.     }
  2362.   else
  2363. #endif /* USING_SVR4_H */
  2364.     ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
  2365.  
  2366.   /* Handle FP constants specially.  Note that if we have a minimal
  2367.      TOC, things we put here aren't actually in the TOC, so we can allow
  2368.      FP constants.  */
  2369.   if (GET_CODE (x) == CONST_DOUBLE
  2370.       && GET_MODE (x) == DFmode
  2371.       && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
  2372.     {
  2373.       REAL_VALUE_TYPE r;
  2374.       long l[2];
  2375.  
  2376.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2377.       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
  2378.       if (TARGET_MINIMAL_TOC)
  2379.     fprintf (file, "\t.long %ld\n\t.long %ld\n", l[0], l[1]);
  2380.       else
  2381.     fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
  2382.          l[0], l[1], l[0], l[1]);
  2383.       return;
  2384.     }
  2385.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
  2386.        && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
  2387.     {
  2388.       rtx val = operand_subword (x, 0, 0, SFmode);
  2389.  
  2390.       if (val == 0 || GET_CODE (val) != CONST_INT)
  2391.     abort ();
  2392.  
  2393.       if (TARGET_MINIMAL_TOC)
  2394.     fprintf (file, "\t.long %d\n", INTVAL (val));
  2395.       else
  2396.     fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
  2397.       return;
  2398.     }
  2399.  
  2400.   if (GET_CODE (x) == CONST)
  2401.     {
  2402.       base = XEXP (XEXP (x, 0), 0);
  2403.       offset = INTVAL (XEXP (XEXP (x, 0), 1));
  2404.     }
  2405.   
  2406.   if (GET_CODE (base) == SYMBOL_REF)
  2407.     name = XSTR (base, 0);
  2408.   else if (GET_CODE (base) == LABEL_REF)
  2409.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
  2410.   else if (GET_CODE (base) == CODE_LABEL)
  2411.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
  2412.   else
  2413.     abort ();
  2414.  
  2415.   if (TARGET_MINIMAL_TOC)
  2416.     fprintf (file, "\t.long ");
  2417.   else
  2418.     {
  2419.       fprintf (file, "\t.tc ");
  2420.       RS6000_OUTPUT_BASENAME (file, name);
  2421.  
  2422.       if (offset < 0)
  2423.     fprintf (file, ".N%d", - offset);
  2424.       else if (offset)
  2425.     fprintf (file, ".P%d", offset);
  2426.  
  2427.       fprintf (file, "[TC],");
  2428.     }
  2429.   output_addr_const (file, x);
  2430.   fprintf (file, "\n");
  2431. }
  2432.  
  2433. /* Output an assembler pseudo-op to write an ASCII string of N characters
  2434.    starting at P to FILE.
  2435.  
  2436.    On the RS/6000, we have to do this using the .byte operation and
  2437.    write out special characters outside the quoted string.
  2438.    Also, the assembler is broken; very long strings are truncated,
  2439.    so we must artificially break them up early. */
  2440.  
  2441. void
  2442. output_ascii (file, p, n)
  2443.      FILE *file;
  2444.      char *p;
  2445.      int n;
  2446. {
  2447.   char c;
  2448.   int i, count_string;
  2449.   char *for_string = "\t.byte \"";
  2450.   char *for_decimal = "\t.byte ";
  2451.   char *to_close = NULL;
  2452.  
  2453.   count_string = 0;
  2454.   for (i = 0; i < n; i++)
  2455.     {
  2456.       c = *p++;
  2457.       if (c >= ' ' && c < 0177)
  2458.     {
  2459.       if (for_string)
  2460.         fputs (for_string, file);
  2461.       putc (c, file);
  2462.  
  2463.       /* Write two quotes to get one.  */
  2464.       if (c == '"')
  2465.         {
  2466.           putc (c, file);
  2467.           ++count_string;
  2468.         }
  2469.  
  2470.       for_string = NULL;
  2471.       for_decimal = "\"\n\t.byte ";
  2472.       to_close = "\"\n";
  2473.       ++count_string;
  2474.  
  2475.       if (count_string >= 512)
  2476.         {
  2477.           fputs (to_close, file);
  2478.  
  2479.           for_string = "\t.byte \"";
  2480.           for_decimal = "\t.byte ";
  2481.           to_close = NULL;
  2482.           count_string = 0;
  2483.         }
  2484.     }
  2485.       else
  2486.     {
  2487.       if (for_decimal)
  2488.         fputs (for_decimal, file);
  2489.       fprintf (file, "%d", c);
  2490.  
  2491.       for_string = "\n\t.byte \"";
  2492.       for_decimal = ", ";
  2493.       to_close = "\n";
  2494.       count_string = 0;
  2495.     }
  2496.     }
  2497.  
  2498.   /* Now close the string if we have written one.  Then end the line.  */
  2499.   if (to_close)
  2500.     fprintf (file, to_close);
  2501. }
  2502.  
  2503. /* Generate a unique section name for FILENAME for a section type
  2504.    represented by SECTION_DESC.  Output goes into BUF.
  2505.  
  2506.    SECTION_DESC can be any string, as long as it is different for each
  2507.    possible section type.
  2508.  
  2509.    We name the section in the same manner as xlc.  The name begins with an
  2510.    underscore followed by the filename (after stripping any leading directory
  2511.    names) with the last period replaced by the string SECTION_DESC.  If
  2512.    FILENAME does not contain a period, SECTION_DESC is appended to the end of
  2513.    the name.  */
  2514.  
  2515. void
  2516. rs6000_gen_section_name (buf, filename, section_desc)
  2517.      char **buf;
  2518.      char *filename;
  2519.      char *section_desc;
  2520. {
  2521.   char *q, *after_last_slash, *last_period;
  2522.   char *p;
  2523.   int len;
  2524.  
  2525.   after_last_slash = filename;
  2526.   for (q = filename; *q; q++)
  2527.     {
  2528.       if (*q == '/')
  2529.     after_last_slash = q + 1;
  2530.       else if (*q == '.')
  2531.     last_period = q;
  2532.     }
  2533.  
  2534.   len = strlen (after_last_slash) + strlen (section_desc) + 2;
  2535.   *buf = (char *) permalloc (len);
  2536.  
  2537.   p = *buf;
  2538.   *p++ = '_';
  2539.  
  2540.   for (q = after_last_slash; *q; q++)
  2541.     {
  2542.       if (q == last_period)
  2543.         {
  2544.       strcpy (p, section_desc);
  2545.       p += strlen (section_desc);
  2546.         }
  2547.  
  2548.       else if (isalnum (*q))
  2549.         *p++ = *q;
  2550.     }
  2551.  
  2552.   if (last_period == 0)
  2553.     strcpy (p, section_desc);
  2554.   else
  2555.     *p = '\0';
  2556. }
  2557.  
  2558. /* Write function profiler code. */
  2559.  
  2560. void
  2561. output_function_profiler (file, labelno)
  2562.   FILE *file;
  2563.   int labelno;
  2564. {
  2565. #ifdef USING_SVR4_H
  2566.   abort ();
  2567. #else
  2568.   /* The last used parameter register.  */
  2569.   int last_parm_reg;
  2570.   int i, j;
  2571.   char buf[100];
  2572.  
  2573.   /* Set up a TOC entry for the profiler label.  */
  2574.   toc_section ();
  2575.   ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
  2576.   ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
  2577.   if (TARGET_MINIMAL_TOC)
  2578.     {
  2579.       fprintf (file, "\t.long ");
  2580.       assemble_name (file, buf);
  2581.       fprintf (file, "\n");
  2582.     }
  2583.   else
  2584.     {
  2585.       fprintf (file, "\t.tc\t");
  2586.       assemble_name (file, buf);
  2587.       fprintf (file, "[TC],");
  2588.       assemble_name (file, buf);
  2589.       fprintf (file, "\n");
  2590.     }
  2591.   text_section ();
  2592.  
  2593.   /* Figure out last used parameter register.  The proper thing to do is
  2594.      to walk incoming args of the function.  A function might have live
  2595.      parameter registers even if it has no incoming args.  */
  2596.  
  2597.   for (last_parm_reg = 10;
  2598.        last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
  2599.        last_parm_reg--)
  2600.     ;
  2601.  
  2602.   /* Save parameter registers in regs 23-30.  Don't overwrite reg 31, since
  2603.      it might be set up as the frame pointer.  */
  2604.  
  2605.   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
  2606.     fprintf (file, "\tai %d,%d,0\n", j, i);
  2607.  
  2608.   /* Load location address into r3, and call mcount.  */
  2609.  
  2610.   ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
  2611.   fprintf (file, "\tl 3,");
  2612.   assemble_name (file, buf);
  2613.   fprintf (file, "(2)\n\tbl .mcount\n");
  2614.  
  2615.   /* Restore parameter registers.  */
  2616.  
  2617.   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
  2618.     fprintf (file, "\tai %d,%d,0\n", i, j);
  2619. #endif
  2620. }
  2621.  
  2622. /* Adjust the cost of a scheduling dependency.  Return the new cost of
  2623.    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
  2624.  
  2625. int
  2626. rs6000_adjust_cost (insn, link, dep_insn, cost)
  2627.      rtx insn;
  2628.      rtx link;
  2629.      rtx dep_insn;
  2630.      int cost;
  2631. {
  2632.   if (! recog_memoized (insn))
  2633.     return 0;
  2634.  
  2635.   if (REG_NOTE_KIND (link) != 0)
  2636.     return 0;
  2637.  
  2638.   if (REG_NOTE_KIND (link) == 0)
  2639.     {
  2640.       /* Data dependency; DEP_INSN writes a register that INSN reads some
  2641.      cycles later.  */
  2642.  
  2643.       /* Tell the first scheduling pass about the latency between a mtctr
  2644.      and bctr (and mtlr and br/blr).  The first scheduling pass will not
  2645.      know about this latency since the mtctr instruction, which has the
  2646.      latency associated to it, will be generated by reload.  */
  2647.       if (get_attr_type (insn) == TYPE_JMPREG)
  2648.     return TARGET_POWER ? 5 : 4;
  2649.  
  2650.       /* Fall out to return default cost.  */
  2651.     }
  2652.  
  2653.   return cost;
  2654. }
  2655.